/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package TimeRecording.widgets;

import java.text.DecimalFormat;
import org.jdesktop.beansbinding.Converter;

/**
 *
 * @author david
 */
public class DoubleConverter extends Converter<Double, String> {

    private DecimalFormat formatter = new DecimalFormat("0.00");

    @Override
    public String convertForward(Double value) {
        if (value == null) {
            value = 0.0;
        }
        return formatter.format(value);
    }

    @Override
    public Double convertReverse(String value) {
        try {
            return Double.parseDouble(value);
        } catch (NumberFormatException ex) {
            return null;
        }
    }

    public Double round(Double value) {
        return convertReverse(convertForward(value));
    }
}
